<template>
    <div class="index-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="赛事名称" prop="name">
                    <el-input class="w-[280px]" v-model="queryParams.name" />
                </el-form-item>
                <el-form-item label="赛事地点" prop="address">
                    <el-input class="w-[280px]" v-model="queryParams.address" />
                </el-form-item>
                <el-form-item label="赛事时间" prop="playTime">
                    <el-input class="w-[280px]" v-model="queryParams.playTime" />
                </el-form-item>
                <el-form-item label="比赛方式" prop="playType">
                    <el-select v-model="queryParams.playType" class="w-[280px]" clearable>
                        <el-option label="请选择字典生成" value="" />
                    </el-select>
                </el-form-item>
                <el-form-item label="赛事赛程" prop="schedule">
                    <el-input class="w-[280px]" v-model="queryParams.schedule" />
                </el-form-item>
                <el-form-item label="组织方&nbsp;&nbsp;&nbsp;" prop="orgParty">
                    <el-input class="w-[280px]" v-model="queryParams.orgParty" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <el-button v-perms="['competition.list/add']" type="primary" @click="handleAdd()">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    新增
                </el-button>
            </div>
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="名称" prop="name" min-width="100" />
                <el-table-column label="封面" min-width="100">
                    <template #default="{ row }">
                        <image-contain
                            v-if="row.cover"
                            :src="row.cover"
                            :width="60"
                            :height="45"
                            :preview-src-list="[row.cover]"
                            preview-teleported
                            fit="contain"
                        />
                    </template>
                </el-table-column>
                <el-table-column label="地点" prop="address" min-width="100" />
                <el-table-column label="比赛时间" prop="playTime" min-width="130" />
                <el-table-column label="比赛方式" min-width="100">
                    <template #default="{ row }">
                        <el-tag v-if="row.playType == 0">全类型</el-tag>
                        <el-tag type="success" v-else-if="row.playType == 1">男单打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 2">女单打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 12">男/女-单打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 3">男双打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 13">男单-男双打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 23">女单-男双打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 4">女双打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 14">男单-女双打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 24">女单-女双打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 34">男/女-双打</el-tag>
                      <el-tag type="danger" v-else-if="row.playType == 1234">男/女-单打/双打</el-tag>
                        <el-tag type="danger" v-else-if="row.playType == 5">男女混打</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="赛程" prop="schedule" min-width="100" />
                <el-table-column label="状态" prop="status" min-width="100">
                  <template #default="{ row }">
                    <el-tag type="success" v-if="row.status == 1">正常</el-tag>
                    <el-tag type="success" v-else-if="row.status == 5">结束</el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="组织方" prop="orgParty" min-width="100" />
                <el-table-column label="创建者" prop="createId" min-width="100" />
                <el-table-column label="创建时间" prop="createTime" min-width="100" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['competition.list/edit']"
                            type="primary"
                            link
                            @click="handleEdit(row)"
                        >
                            编辑
                        </el-button>
                        <el-button
                            v-perms="['competition.list/del']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
<!--        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />-->
    </div>
</template>
<script lang="ts" setup name="competition">
import { competitionDelete, competitionLists } from '@/api/competition/competition'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'

// import EditPopup from './edit.vue'
// const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    name: '',
    cover: '',
    address: '',
    playTime: '',
    playType: '',
    schedule: '',
    status: '',
    orgParty: '',
    orgId: '',
    createId: '',
    updateId: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: competitionLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    // editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    // editRef.value?.open('edit')
    // editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await competitionDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
